<?php
// **************************************************************
//  Copyright 2007 AMC
//  Glenview, Illinois
//
//  File:      index.php
//  Author:    Rakesh verma
//  Function:  Page for URL extraction
//
//  Created: 06/25/09
//  Version: 1.0
//
//  Modified:
// **************************************************************
require_once 'init.php';
// pull any passed variables
$task    = $_REQUEST['task'];
switch ($task)
{
    case 'csv': // CSV export
        $filename = "log_export_" . date('Y_m_d_H_i') . ".csv";
        // stream the file to the user
        header("Content-type: application/octet-stream");
        //tell the browser what to do with this
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Pragma: no-cache");
        header("Expires: 0");
        $file_handle = fopen(APP_BASE_PATH."/ws_joomla_import/log.csv", "r");
        $row = array('URL','Status', 'Date & Time');
        echo implode(',',$row)."\n";

        while (!feof($file_handle) ) {
        $line_of_text = fgetcsv($file_handle, 0);
        $row          = array();
        $row[0]       =  $line_of_text[1];
        $row[1]       =  $line_of_text[2];
        $row[2]       =  $line_of_text[3];
        echo '"'.implode('","',$row).'"'."\n";
        }
       break;

    case 'word': // word export

        $filename = "log_export_" . date('Y_m_d_H_i') . ".doc";
        // stream it as a file
        header ("Content-type: application/octet-stream");
        header ("Content-Disposition: attachment; filename=" . $filename);
        header ("Pragma: no-cache");
        header ("Expires: 0");

        include ABSTRACT_POPUP_HEADER;
        include 'templates/tpl_reportcsv.php';
        include ABSTRACT_POPUP_FOOTER;
        break;

   default: // html view
       include ABSTRACT_POPUP_HEADER;
       $page_data = array('csv_export'=> true);
       include 'templates/tpl_report_navigation.php';
       include 'templates/tpl_reportcsv.php';
       include ABSTRACT_POPUP_FOOTER;
}

 ?>
